package com.example.mform.controller;

import com.example.mform.entity.FillForm;
import com.example.mform.entity.Question;
import com.example.mform.service.FillFormService;
import com.example.mform.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shishuqian
 * date 2020/12/16
 * time 21:37
 **/
@RestController
@RequestMapping("/fillForm")
public class FillFormController {

    @Autowired
    private FillFormService fillFormService;

    @PostMapping("/save")
    public void save(@RequestBody List<FillForm> fillForms){
        fillFormService.save(fillForms);
    }

    @GetMapping("/findAll")
    public List<FillForm> findAll(){
        return fillFormService.findAll();
    }

    @GetMapping("/findById/{id}")
    public FillForm findById(@PathVariable("id") Long id){
        return fillFormService.findById(id);
    }



    @DeleteMapping("/deleteById/{id}")
    public void  deleteById(@PathVariable("id") Long id){
        fillFormService.deleteById(id);
    }

    @GetMapping("/queryAnswer/{question_id}")
    public List<String> queryAnswer(@PathVariable("question_id") Long question_id){
        return fillFormService.queryAnswer(question_id);
    }

    @GetMapping("/countPeople/{form_id}")
    public int countPeople(@PathVariable("form_id") Long form_id){
        return fillFormService.countPeople(form_id);
    }

    @GetMapping("/countChoice/{answer}")
    public int countChoice(@PathVariable("answer") Long answer){
        return fillFormService.countChoice(answer);
    }

    @GetMapping("/countResult/{form_id}")
    public List<Question> countResult(@PathVariable("form_id") Long form_id){
        return fillFormService.countResult(form_id);
    }
}
